<template>
  <div class="search-table-page">
    <Row type="flex"
         justify="space-between"
         class="row-operation">
      <i-col span="24">
      <search-form @search="handleSearch"></search-form>
      </i-col>
      <!-- <i-col span="8"
           class="col-right">
      <add class="spteen"
           @getList="getTableData"></add>
      <Poptip confirm
              title="确定删除？"
              @on-ok="okdelete">
        <Button icon="md-trash"
                type="error">删除</Button>
      </Poptip>
      </i-col> -->
    </Row>
    <table-page :loading="loading"
                :columns1="columns1"
                :data1="tableData"
                :noData="noData"
                :currentPage="currentPage"
                :totalPage="totalPage"
                :pageSize="pageSize"
                @multi-select="multiSelect"
                @change-page="changePage"
                @change-page-size="changPageSize">
    </table-page>
    <!-- <edit ref="edit"
          @getList="getTableData"></edit> -->
  </div>
</template>

<script>
import edit from './edit/edit'
import searchForm from './search-form/search-form'
import tablePage from '_c/table-page/table-page'
import { getUserbonusList } from '@/api/user'

export default {
  name: 'user-manage',
  components: {
    edit,
    searchForm,
    tablePage
  },
  data () {
    return {
      exportLoading: false,
      loading: false,
      columns1: [
        {
          type: 'index',
          width: 60,
          align: 'center'
        },
        {
          title: '用户名',
          key: 'PhoneNum'
        },
        {
          title: '交易订单号',
          key: 'OrderNum'
        },
        {
          title: '来源',
          key: 'RewardSource'
        },
        {
          title: '类型',
          key: 'RewardType',
          render: (h, params) => {
            const row = params.row
            const text = row.RewardType === 0 ? '收入' : '支出'
            return h('span', {}, text)
          }
        },
        {
          title: '积分变化量',
          key: 'RewardVariation'
        },
        {
          title: '状态',
          key: 'Status'
        },
        {
          title: '改变时间',
          key: 'ChangeTime'
        },
        {
          title: '备注',
          key: 'Remarks'
        }
        // {
        //   title: '操作',
        //   key: 'handle',
        //   width: 80,
        //   align: 'center',
        //   render: (h, params) => {
        //     return h('div', [
        //       h('Button', {
        //         props: {
        //           type: 'primary',
        //           size: 'small'
        //         },
        //         on: {
        //           click: () => {
        //             this.$refs.edit.getItem(params.row.UserID)
        //           }
        //         }
        //       }, '编辑')
        //     ])
        //   }
        // }
      ],
      noData: '暂无数据',
      currentPage: 1,
      totalPage: 0,
      pageSize: 10,
      tableData: [],
      selectedIds: [],
      uplistsData: {
        'PageIndex': '1',
        'PageSize': '10',
        'Search': []
      }
    }
  },
  mounted () {
    this.init()
    this.getTableData()
  },
  methods: {
    init () {
      this.uplistsData = {
        'PageIndex': '1',
        'PageSize': '10',
        'Search': []
      }
    },
    // 获取表格数据信息
    getTableData (parameter) {
      this.loading = true
      parameter = this.uplistsData
      getUserbonusList(parameter).then(res => {
        if (res.data.success) {
          this.totalPage = res.data.data.TotalCount
          this.currentPage = res.data.data.CurrentPageIndex
          this.tableData = res.data.data.aaData
          this.loading = false
        } else {
          this.$Message.info(res.data.msg)
          this.loading = true
        }
      }).catch(err => {
        console.log(err)
      })
    },
    // 页码切换
    changePage (page) {
      this.currentPage = page
      this.uplistsData.PageIndex = page
      this.getTableData()
    },
    // 切换每页显示多少条数据
    changPageSize (pageSize) {
      this.init()
      this.pageSize = pageSize
      this.uplistsData.PageSize = pageSize
      this.getTableData()
    },
    handleSearch (searchContent) {
      this.uplistsData.Search = searchContent
      this.getTableData(this.uplistsData)
    },
    // 多选
    multiSelect (selection) {
      this.selectedIds = selection.map(item => item.Id)
    }
  }
}
</script>

<style lang="less" scoped>
.search-table-page {
  padding: 20px;
  min-height: 85vh;
  background-color: #fff;
  .row-operation {
    margin-bottom: 20px;
    .col-right {
      text-align: right;
      .spteen {
        margin-left: 5px;
      }
    }
  }
}
</style>
